﻿<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>教务管理系统 - 作业提交</title>
    <link href="${pageContext.request.contextPath}/resources/bootstrap5/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons - 本地版本 -->
    <link href="${pageContext.request.contextPath}/resources/bootstrap-icons/1.11.3/bootstrap-icons.css" rel="stylesheet">
    <!-- Bootstrap Icons - 备用CDN -->
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap-icons/1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
    <!-- 第二个备用CDN -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
    <style>
        body {
            font-family: "Microsoft YaHei", sans-serif;
            background-color: #f5f5f5;
            margin: 0;
            padding: 0;
        }

        .header {
            background-color: #1976d2;
            color: white;
            padding: 10px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            position: fixed;
            width: 100%;
            top: 0;
            z-index: 1000;
        }

        .header-left {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .header h2 {
            margin: 0;
            font-size: 1.5rem;
            display: flex;
            align-items: center;
        }

        .header h2 img {
            height: 36px;
            margin-right: 10px;
        }

        .header .breadcrumb {
            margin: 0;
            background: transparent;
            color: white;
        }

        .header .breadcrumb a {
            color: rgba(255,255,255,0.8);
            text-decoration: none;
        }

        .header .breadcrumb a:hover {
            color: white;
        }

        .header .breadcrumb-item.active {
            color: white;
        }

        .header .breadcrumb-item+.breadcrumb-item::before {
            color: rgba(255,255,255,0.6);
        }

        /* 内容区样式 */
        .content {
            margin-left: 250px;
            padding: 76px 20px 20px;
        }

        /* 作业相关样式 */
        .homework-title {
            font-weight: 600;
            color: #2c3e50;
        }

        .homework-content {
            color: #6c757d;
            font-size: 0.9rem;
            max-width: 200px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .score-badge {
            display: inline-block;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 0.8rem;
            font-weight: 500;
        }

        .score-excellent {
            background-color: #d4edda;
            color: #155724;
        }

        .score-good {
            background-color: #cce5ff;
            color: #004085;
        }

        .score-average {
            background-color: #fff3cd;
            color: #856404;
        }

        .score-poor {
            background-color: #f8d7da;
            color: #721c24;
        }

        .score-ungraded {
            background-color: #e2e3e5;
            color: #6c757d;
        }

        .empty-state {
            text-align: center;
            padding: 50px 20px;
            color: #6c757d;
        }

        .empty-state i {
            font-size: 4rem;
            margin-bottom: 20px;
            color: #dee2e6;
        }

        @media (max-width: 768px) {
            .content {
                margin-left: 0;
            }
        }

        /* 用户名下拉菜单样式 */
        .header-user {
            display: flex;
            align-items: center;
            position: relative;
        }
        .header-user-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            margin-right: 8px;
            object-fit: cover;
            background: #fff;
            cursor: pointer;
            transition: transform 0.2s;
        }
        .header-user-avatar:hover {
            transform: scale(1.1);
        }
        .header-user-name {
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
        }
        .user-dropdown {
            position: absolute;
            top: 100%;
            right: 0;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            min-width: 160px;
            z-index: 1001;
            opacity: 0;
            visibility: hidden;
            transform: translateY(-10px);
            transition: all 0.3s ease;
            margin-top: 8px;
        }
        .user-dropdown.show {
            opacity: 1;
            visibility: visible;
            transform: translateY(0);
        }
        .user-dropdown::before {
            content: '';
            position: absolute;
            top: -6px;
            right: 16px;
            width: 12px;
            height: 12px;
            background: #fff;
            transform: rotate(45deg);
            border-left: 1px solid rgba(0,0,0,0.08);
            border-top: 1px solid rgba(0,0,0,0.08);
        }
        .user-dropdown a {
            display: block;
            padding: 10px 16px;
            color: #333;
            text-decoration: none;
            font-size: 0.9rem;
            transition: background-color 0.2s;
        }
        .user-dropdown a:hover {
            background-color: #f8f9fa;
        }
        .user-dropdown a:first-child {
            border-radius: 8px 8px 0 0;
        }
        .user-dropdown a:last-child {
            border-radius: 0 0 8px 8px;
            border-top: 1px solid #eee;
            color: #dc3545;
        }
        .user-dropdown a:last-child:hover {
            background-color: #fff5f5;
        }

        .user-dropdown-item {
            display: flex;
            align-items: center;
            padding: 12px 16px;
            color: #333;
            text-decoration: none;
            transition: background 0.2s;
            border-bottom: 1px solid #f0f0f0;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
        }
        .user-dropdown-item:last-child {
            border-bottom: none;
        }
        .user-dropdown-item:hover {
            background: #f8f9fa;
            color: #2196f3;
        }
        .user-dropdown-item i {
            margin-right: 8px;
            width: 16px;
            text-align: center;
        }

        .card {
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
            margin-bottom: 20px;
            overflow: hidden;
        }

        .card-header {
            padding: 15px 20px;
            background-color: white;
            border-bottom: 1px solid #eee;
            font-weight: 600;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .card-body {
            padding: 20px;
        }

        .table {
            margin-bottom: 0;
        }

        .table th {
            background-color: #f8f9fa;
            border-top: none;
            font-weight: 600;
            color: #495057;
        }

        .table-hover tbody tr:hover {
            background-color: rgba(0,123,255,.075);
        }

        .btn {
            border-radius: 6px;
            padding: 6px 12px;
            font-size: 14px;
        }

        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
        }

        .btn-primary:hover {
            background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
            border: none;
        }

        .btn-success {
            background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
            border: none;
        }

        .btn-success:hover {
            background: linear-gradient(135deg, #3d8bfe 0%, #00d9fe 100%);
            border: none;
        }

        .btn-danger {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            border: none;
        }

        .btn-danger:hover {
            background: linear-gradient(135deg, #ee82f7 0%, #f34458 100%);
            border: none;
        }

        .pagination {
            margin-bottom: 0;
        }

        .pagination .page-link {
            border: 1px solid #dee2e6;
            color: #495057;
        }

        .pagination .page-item.active .page-link {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-color: #667eea;
        }
    </style>
</head>
<body>
<!-- 顶部导航栏 -->
<div class="header">
    <div class="header-left">
        <h2><img src="${pageContext.request.contextPath}/resources/images/logo.png" alt="Logo"> 教务管理系统</h2>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="${pageContext.request.contextPath}/student/home">首页</a></li>
                <li class="breadcrumb-item active">作业提交</li>
            </ol>
        </nav>
    </div>

    <!-- 用户名下拉菜单 -->
    <div class="header-user" id="userDropdownContainer">
        <img src="${pageContext.request.contextPath}/resources/images/baimao.png" class="header-user-avatar" alt="用户头像" id="userAvatar">
        <span class="header-user-name" id="userName">
            <c:choose>
                <c:when test="${not empty currentStudent and not empty currentStudent.user and not empty currentStudent.user.realName}">
                    ${currentStudent.user.realName}
                </c:when>
                <c:when test="${not empty sessionScope.loggedInUser and not empty sessionScope.loggedInUser.realName}">
                    ${sessionScope.loggedInUser.realName}
                </c:when>
                <c:when test="${not empty sessionScope.loggedInUser and not empty sessionScope.loggedInUser.username}">
                    ${sessionScope.loggedInUser.username}
                </c:when>
                <c:otherwise>
                    学生
                </c:otherwise>
            </c:choose>
        </span>
        <div class="user-dropdown" id="userDropdown">
            <a href="#" class="user-dropdown-item" onclick="showProfileModal()">
                <i class="bi bi-person-circle"></i>
                个人信息
            </a>
            <a href="${pageContext.request.contextPath}/student/changePassword" class="user-dropdown-item">
                <i class="bi bi-key"></i>
                修改密码
            </a>
            <a href="${pageContext.request.contextPath}/user/logout" class="user-dropdown-item">
                <i class="bi bi-box-arrow-right"></i>
                退出系统
            </a>
        </div>
    </div>
</div>

<!-- 侧边栏 -->
<%@ include file="../common/student-sidebar.jsp" %>

<!-- 内容区 -->
<div class="content">
    <c:if test="${not empty error}">
        <div class="alert alert-danger" role="alert">
            <i class="bi bi-exclamation-triangle"></i> ${error}
        </div>
    </c:if>

    <!-- 页面标题和操作按钮 -->
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h3 class="mb-0">
            <i class="bi bi-file-earmark-text text-primary"></i>
            作业提交管理
        </h3>
        <button type="button" class="btn btn-primary" onclick="showSubmitModal()">
            <i class="bi bi-plus-circle"></i> 提交作业
        </button>
    </div>

    <!-- 搜索和筛选 -->
    <div class="card mb-4">
        <div class="card-body">
            <form method="get" action="${pageContext.request.contextPath}/student/homework">
                <div class="row g-3">
                    <div class="col-md-6">
                        <label for="courseNameSearch" class="form-label">
                            <i class="bi bi-search"></i> 课程名称
                        </label>
                        <input type="text" class="form-control" id="courseNameSearch" name="courseNameSearch"
                               value="${courseNameSearch}" placeholder="请输入课程名称">
                    </div>
                    <div class="col-md-3">
                        <label class="form-label">&nbsp;</label>
                        <div class="d-grid gap-2 d-md-flex">
                            <button type="submit" class="btn btn-primary">
                                <i class="bi bi-search"></i> 查询
                            </button>
                            <a href="${pageContext.request.contextPath}/student/homework" class="btn btn-outline-secondary">
                                <i class="bi bi-arrow-clockwise"></i> 重置
                            </a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <!-- 作业提交列表 -->
    <div class="card">
        <div class="card-header">
            <span><i class="bi bi-list-ul"></i> 我的作业提交</span>
            <span class="text-muted">共 ${totalRecords} 条记录</span>
        </div>
        <div class="card-body p-0">
            <c:choose>
                <c:when test="${not empty homeworkSubmissions}">
                    <div class="table-responsive">
                        <table class="table table-hover mb-0">
                            <thead>
                            <tr>
                                <th style="width: 80px;">序号</th>
                                <th>作业说明</th>
                                <th>学生姓名</th>
                                <th>课程</th>
                                <th>授课教师</th>
                                <th>作业文件</th>
                                <th style="width: 100px;">评分</th>
                                <th style="width: 120px;">说明</th>
                                <th style="width: 120px;">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${homeworkSubmissions}" var="submission" varStatus="status">
                                <tr>
                                    <td>${(currentPage - 1) * pageSize + status.index + 1}</td>
                                    <td>
                                        <div class="homework-title">
                                            <c:choose>
                                                <c:when test="${not empty submission.homework.title}">
                                                    ${submission.homework.title}
                                                </c:when>
                                                <c:otherwise>
                                                    未知作业
                                                </c:otherwise>
                                            </c:choose>
                                        </div>
                                        <div class="homework-content" title="${submission.content}">
                                                ${submission.content}
                                        </div>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${not empty submission.student.user.realName}">
                                                ${submission.student.user.realName}
                                            </c:when>
                                            <c:otherwise>
                                                ${submission.student.studentNo}
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${not empty submission.homework.course.name}">
                                                ${submission.homework.course.name}
                                            </c:when>
                                            <c:otherwise>
                                                未知课程
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${not empty submission.homework.course.teacher.user.realName}">
                                                ${submission.homework.course.teacher.user.realName}
                                            </c:when>
                                            <c:otherwise>
                                                未分配
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${not empty submission.fileUrl}">
                                                <a href="${pageContext.request.contextPath}/student/homework/download/${submission.id}"
                                                   class="btn btn-sm btn-outline-success" title="下载文件">
                                                    <i class="bi bi-download"></i> 下载
                                                </a>
                                            </c:when>
                                            <c:otherwise>
                                                <span class="text-muted">无文件</span>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${not empty submission.score}">
                                                <c:choose>
                                                    <c:when test="${submission.score >= 90}">
                                                        <span class="score-badge score-excellent">${submission.score}分</span>
                                                    </c:when>
                                                    <c:when test="${submission.score >= 80}">
                                                        <span class="score-badge score-good">${submission.score}分</span>
                                                    </c:when>
                                                    <c:when test="${submission.score >= 60}">
                                                        <span class="score-badge score-average">${submission.score}分</span>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <span class="score-badge score-poor">${submission.score}分</span>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:when>
                                            <c:otherwise>
                                                <span class="score-badge score-ungraded">未评分</span>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <small class="text-muted">
                                            提交时间：${submission.createTimeStr}
                                        </small>
                                    </td>
                                    <td>
                                        <div class="btn-group" role="group">
                                            <button type="button" class="btn btn-sm btn-outline-primary"
                                                    onclick="viewSubmission(${submission.id})" title="查看详情">
                                                <i class="bi bi-eye"></i>
                                            </button>
                                            <c:if test="${empty submission.score}">
                                                <button type="button" class="btn btn-sm btn-outline-danger"
                                                        onclick="deleteSubmission(${submission.id})" title="删除">
                                                    <i class="bi bi-trash"></i>
                                                </button>
                                            </c:if>
                                        </div>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>
                </c:when>
                <c:otherwise>
                    <div class="empty-state">
                        <i class="bi bi-file-earmark-text"></i>
                        <h5>暂无作业提交记录</h5>
                        <p class="text-muted">您还没有提交任何作业，点击上面"提交作业"按钮开始提交作业。</p>
                    </div>
                </c:otherwise>
            </c:choose>
        </div>

        <!-- 分页 -->
        <c:if test="${totalPages > 1}">
            <div class="card-footer">
                <nav aria-label="Page navigation">
                    <ul class="pagination justify-content-center mb-0">
                        <li class="page-item ${currentPage == 1 ? 'disabled' : ''}">
                            <a class="page-link" href="?page=${currentPage - 1}&courseNameSearch=${courseNameSearch}">
                                <i class="bi bi-chevron-left"></i> 上一页
                            </a>
                        </li>

                        <c:forEach begin="1" end="${totalPages}" var="i">
                            <c:if test="${i == currentPage || (i >= currentPage - 2 && i <= currentPage + 2)}">
                                <li class="page-item ${i == currentPage ? 'active' : ''}">
                                    <a class="page-link" href="?page=${i}&courseNameSearch=${courseNameSearch}">${i}</a>
                                </li>
                            </c:if>
                        </c:forEach>

                        <li class="page-item ${currentPage == totalPages ? 'disabled' : ''}">
                            <a class="page-link" href="?page=${currentPage + 1}&courseNameSearch=${courseNameSearch}">
                                下一页 <i class="bi bi-chevron-right"></i>
                            </a>
                        </li>
                    </ul>
                </nav>
            </div>
        </c:if>
    </div>
</div>

<!-- 提交作业模态框 -->
<div class="modal fade" id="submitHomeworkModal" tabindex="-1" aria-labelledby="submitHomeworkModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header" style="background-color: #28a745; color: white;">
                <h5 class="modal-title" id="submitHomeworkModalLabel">
                    <i class="bi bi-file-earmark-plus"></i> 提交作业
                </h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form id="submitHomeworkForm" enctype="multipart/form-data">
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label for="courseSelect" class="form-label">
                                <i class="bi bi-book"></i> 选择课程 <span class="text-danger">*</span>
                            </label>
                            <select class="form-select" id="courseSelect" name="courseId" required onchange="loadHomeworksByCourse()">
                                <option value="">请选择课程</option>
                                <c:forEach items="${availableCourses}" var="course">
                                    <option value="${course.id}">${course.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label for="homeworkSelect" class="form-label">
                                <i class="bi bi-file-earmark-text"></i> 选择作业 <span class="text-danger">*</span>
                            </label>
                            <select class="form-select" id="homeworkSelect" name="homeworkId" required>
                                <option value="">请先选择课程</option>
                            </select>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label for="homeworkContent" class="form-label">
                            <i class="bi bi-card-text"></i> 作业内容 <span class="text-danger">*</span>
                        </label>
                        <textarea class="form-control" id="homeworkContent" name="content" rows="6"
                                  placeholder="请输入作业内容，最多2000字" required maxlength="2000"></textarea>
                        <div class="form-text">
                            <span id="contentCount">0</span>/2000 字
                        </div>
                    </div>

                    <div class="mb-3">
                        <label for="fileUpload" class="form-label">
                            <i class="bi bi-paperclip"></i> 作业文件
                        </label>
                        <input type="file" class="form-control" id="fileUpload" name="file"
                               accept=".pdf,.doc,.docx,.txt,.zip,.rar,.jpg,.jpeg,.png">
                        <div class="form-text">支持上传PDF、Word文档、文本文件、压缩包或图片，最大20MB</div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="submitHomework()">
                    <i class="bi bi-check-circle"></i> 提交作业
                </button>
            </div>
        </div>
    </div>
</div>

<!-- 查看作业详情模态框 -->
<div class="modal fade" id="viewSubmissionModal" tabindex="-1" aria-labelledby="viewSubmissionModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header" style="background-color: #17a2b8; color: white;">
                <h5 class="modal-title" id="viewSubmissionModalLabel">
                    <i class="bi bi-eye"></i> 作业详情
                </h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body" id="submissionDetails">
                <!-- 作业详情内容将通过JavaScript动态加载 -->
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 确认删除模态框 -->
<div class="modal fade" id="confirmDeleteModal" tabindex="-1" aria-labelledby="confirmDeleteModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header" style="background-color: #dc3545; color: white;">
                <h5 class="modal-title" id="confirmDeleteModalLabel">
                    <i class="bi bi-exclamation-triangle"></i> 确认删除
                </h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <p>您确定要删除该作业提交吗？此操作无法撤销。</p>
                <input type="hidden" id="deleteSubmissionId" value="">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                <button type="button" class="btn btn-danger" onclick="executeDeleteSubmission()">
                    <i class="bi bi-trash"></i> 确认删除
                </button>
            </div>
        </div>
    </div>
</div>

<!-- 个人信息模态框 -->
<div class="modal fade" id="profileModal" tabindex="-1" aria-labelledby="profileModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="border-radius: 12px;">
            <div class="modal-header" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 12px 12px 0 0;">
                <h5 class="modal-title" id="profileModalLabel">
                    <i class="bi bi-person-circle"></i> 个人信息
                </h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body" style="padding: 30px;">
                <c:if test="${not empty currentStudent}">
                    <div class="row mb-4">
                        <div class="col-12 text-center">
                            <div style="width: 80px; height: 80px; border-radius: 50%; margin: 0 auto 15px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); display: flex; align-items: center; justify-content: center; color: white; font-size: 2rem;">
                                <i class="bi bi-person-circle"></i>
                            </div>
                            <h5 class="mb-1">
                                <c:choose>
                                    <c:when test="${not empty currentStudent.user.realName}">
                                        ${currentStudent.user.realName}
                                    </c:when>
                                    <c:otherwise>
                                        学生信息
                                    </c:otherwise>
                                </c:choose>
                            </h5>
                            <p class="text-muted mb-0">学生个人信息详情</p>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-person me-2"></i>姓名</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.user.realName}">
                                            ${currentStudent.user.realName}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未填写</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-card-text me-2"></i>学号</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.studentNo}">
                                            ${currentStudent.studentNo}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未填写</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-person-badge me-2"></i>用户名</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.user.username}">
                                            ${currentStudent.user.username}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未填写</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-gender-ambiguous me-2"></i>性别</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${currentStudent.gender == 1}">
                                            <span class="badge" style="background: #e3f2fd; color: #1976d2;">男</span>
                                        </c:when>
                                        <c:when test="${currentStudent.gender == 0}">
                                            <span class="badge" style="background: #fce4ec; color: #e91e63;">女</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未填写</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-building me-2"></i>班级</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.clazz and not empty currentStudent.clazz.name}">
                                            ${currentStudent.clazz.name}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未填写</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-mortarboard me-2"></i>专业</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.clazz and not empty currentStudent.clazz.major and not empty currentStudent.clazz.major.name}">
                                            ${currentStudent.clazz.major.name}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未填写</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-bank me-2"></i>学院</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.clazz and not empty currentStudent.clazz.major and not empty currentStudent.clazz.major.college and not empty currentStudent.clazz.major.college.name}">
                                            ${currentStudent.clazz.major.college.name}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未分配学院</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-envelope me-2"></i>电子邮箱</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.email}">
                                            ${currentStudent.email}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">
                                <strong style="color: #667eea;"><i class="bi bi-telephone me-2"></i>联系电话</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.phone}">
                                            ${currentStudent.phone}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                    </div>
                </c:if>
                
                <c:if test="${empty currentStudent}">
                    <div class="text-center py-5">
                        <i class="bi bi-exclamation-circle text-warning" style="font-size: 3rem;"></i>
                        <h5 class="mt-3">无法获取学生信息</h5>
                        <p class="text-muted">请联系管理员或重新登录</p>
                    </div>
                </c:if>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                <a href="${pageContext.request.contextPath}/student/changePassword" class="btn" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white;">
                    <i class="bi bi-key me-1"></i>修改密码
                </a>
            </div>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/resources/bootstrap5/jquery-3.6.0.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/bootstrap5/js/bootstrap.bundle.min.js"></script>
<script>
    // 等待jQuery和DOM加载完成
    $(document).ready(function() {
        // 侧边栏菜单折叠/展开
        window.toggleSubmenu = function(element) {
            const parentLi = element.closest('li');
            const isOpen = parentLi.classList.contains('open');

            // 关闭所有其他打开的子菜单
            document.querySelectorAll('.sidebar-menu > li.open').forEach(li => {
                li.classList.remove('open');
            });

            // 切换当前菜单状态
            if (!isOpen) {
                parentLi.classList.add('open');
            }
        }

        // 用户下拉菜单交互
        const userDropdownContainer = document.getElementById('userDropdownContainer');
        const userDropdown = document.getElementById('userDropdown');
        
        if (userDropdownContainer && userDropdown) {
            userDropdownContainer.addEventListener('click', function(e) {
                e.stopPropagation();
                userDropdown.classList.toggle('show');
            });
            
            document.addEventListener('click', function() {
                userDropdown.classList.remove('show');
            });
        }

        // 显示个人信息模态框
        window.showProfileModal = function() {
            const modal = new bootstrap.Modal(document.getElementById('profileModal'));
            modal.show();
        }

        // 显示提交作业模态框
        window.showSubmitModal = function() {
            // 重置表单
            document.getElementById('submitHomeworkForm').reset();
            document.getElementById('homeworkSelect').innerHTML = '<option value="">请先选择课程</option>';
            document.getElementById('contentCount').textContent = '0';

            // 显示模态框
            const modal = new bootstrap.Modal(document.getElementById('submitHomeworkModal'));
            modal.show();
        }

        // 根据课程加载作业
        window.loadHomeworksByCourse = function() {
            const courseId = document.getElementById('courseSelect').value;
            const homeworkSelect = document.getElementById('homeworkSelect');

            console.log('开始加载作业，课程ID:', courseId); // 调试信息

            if (!courseId) {
                homeworkSelect.innerHTML = '<option value="">请先选择课程</option>';
                return;
            }

            // 显示加载状态
            homeworkSelect.innerHTML = '<option value="">加载中...</option>';

            // 发送AJAX请求获取作业列表
            $.ajax({
                url: '${pageContext.request.contextPath}/student/homework/by-course/' + courseId,
                method: 'GET',
                success: function(response) {
                    console.log('AJAX响应:', response); // 调试信息
                    if (response.success && response.homeworks && response.homeworks.length > 0) {
                        let options = '<option value="">请选择作业</option>';
                        response.homeworks.forEach(homework => {
                            options += '<option value="' + homework.id + '">' + homework.title + '</option>';
                        });
                        homeworkSelect.innerHTML = options;
                        console.log('加载了', response.homeworks.length, '个作业'); // 调试信息
                    } else {
                        homeworkSelect.innerHTML = '<option value="">暂无作业</option>';
                        console.log('没有可用作业，原因:', response.message || '数据为空'); // 调试信息
                    }
                },
                error: function(xhr, status, error) {
                    console.error('加载作业列表失败:', error);
                    console.error('响应状态:', xhr.status);
                    console.error('响应内容:', xhr.responseText);
                    homeworkSelect.innerHTML = '<option value="">加载失败</option>';
                }
            });
        }

        // 提交作业内容字数统计
        $('#homeworkContent').on('input', function() {
            const content = this.value;
            document.getElementById('contentCount').textContent = content.length;
        });

        // 提交作业
        window.submitHomework = function() {
            const form = document.getElementById('submitHomeworkForm');
            const formData = new FormData(form);

            // 验证表单
            if (!form.checkValidity()) {
                form.classList.add('was-validated');
                return;
            }

            // 显示加载状态
            const submitButton = document.querySelector('#submitHomeworkModal .btn-primary');
            const originalText = submitButton.innerHTML;
            submitButton.innerHTML = '<i class="bi bi-spinner bi-spin"></i> 提交中...';
            submitButton.disabled = true;

            // 发送AJAX请求
            $.ajax({
                url: '${pageContext.request.contextPath}/student/homework/submit',
                method: 'POST',
                data: formData,
                contentType: false,
                processData: false,
                success: function(response) {
                    if (response.success) {
                        // 关闭模态框
                        const modal = bootstrap.Modal.getInstance(document.getElementById('submitHomeworkModal'));
                        modal.hide();

                        // 显示成功消息
                        showToast('success', response.message || '作业提交成功！');

                        // 刷新页面
                        setTimeout(() => {
                            location.reload();
                        }, 1500);
                    } else {
                        showToast('error', response.message || '作业提交失败，请重试！');
                    }
                },
                error: function(xhr, status, error) {
                    console.error('作业提交失败:', error);
                    showToast('error', '服务器错误，请重试！');
                },
                complete: function() {
                    // 恢复按钮状态
                    submitButton.innerHTML = originalText;
                    submitButton.disabled = false;
                }
            });
        }

        // 查看作业详情
        window.viewSubmission = function(id) {
            // 显示加载状态
            document.getElementById('submissionDetails').innerHTML = '<div class="text-center py-5"><i class="bi bi-spinner bi-spin text-primary" style="font-size: 2rem;"></i><p class="mt-3">加载中...</p></div>';

            // 发送AJAX请求获取作业详情
            $.ajax({
                url: '${pageContext.request.contextPath}/student/homework/details/' + id,
                method: 'GET',
                success: function(response) {
                    if (response.success && response.data) {
                        const submission = response.data;
                        let detailsHTML = `
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <div class="card border-0 shadow-sm">
                                        <div class="card-header bg-primary text-white">
                                            <h5 class="mb-0"><i class="bi bi-file-text"></i> 作业信息</h5>
                                        </div>
                                        <div class="card-body">
                                            <dl class="row">
                                                <dt class="col-sm-4 text-muted">课程名称:</dt>
                                                <dd class="col-sm-8">${submission.homework.course.name}</dd>

                                                <dt class="col-sm-4 text-muted">作业标题:</dt>
                                                <dd class="col-sm-8">${submission.homework.title}</dd>

                                                <dt class="col-sm-4 text-muted">作业要求:</dt>
                                                <dd class="col-sm-8">${submission.homework.content}</dd>

                                                <dt class="col-sm-4 text-muted">截止日期:</dt>
                                                <dd class="col-sm-8">${submission.homework.deadlineStr}</dd>

                                                <dt class="col-sm-4 text-muted">发布日期:</dt>
                                                <dd class="col-sm-8">${submission.homework.createTimeStr}</dd>
                                            </dl>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-6 mb-3">
                                    <div class="card border-0 shadow-sm">
                                        <div class="card-header bg-success text-white">
                                            <h5 class="mb-0"><i class="bi bi-file-earmark-text"></i> 提交信息</h5>
                                        </div>
                                        <div class="card-body">
                                            <dl class="row">
                                                <dt class="col-sm-4 text-muted">提交学生:</dt>
                                                <dd class="col-sm-8">${submission.student.user.realName || submission.student.studentNo}</dd>

                                                <dt class="col-sm-4 text-muted">提交内容:</dt>
                                                <dd class="col-sm-8">${submission.content}</dd>

                                                <dt class="col-sm-4 text-muted">提交文件:</dt>
                                                <dd class="col-sm-8">
                                                    ${submission.fileUrl ? 
                                                        '<a href="${pageContext.request.contextPath}/student/homework/download/' + submission.id + '" class="btn btn-sm btn-outline-success" title="下载文件"><i class="bi bi-download"></i> 下载</a>' : 
                                                        '<span class="text-muted">无文件</span>'
                                                    }
                                                </dd>

                                                <dt class="col-sm-4 text-muted">提交时间:</dt>
                                                <dd class="col-sm-8">${submission.createTimeStr}</dd>

                                                <dt class="col-sm-4 text-muted">评分:</dt>
                                                <dd class="col-sm-8">
                                                    ${submission.score ? 
                                                        (submission.score >= 90 ? '<span class="score-badge score-excellent">' + submission.score + '分</span>' :
                                                         submission.score >= 80 ? '<span class="score-badge score-good">' + submission.score + '分</span>' :
                                                         submission.score >= 60 ? '<span class="score-badge score-average">' + submission.score + '分</span>' :
                                                         '<span class="score-badge score-poor">' + submission.score + '分</span>') :
                                                        '<span class="score-badge score-ungraded">未评分</span>'
                                                    }
                                                </dd>
                                            </dl>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="mt-4">
                                <div class="card border-0 shadow-sm">
                                    <div class="card-header bg-info text-white">
                                        <h5 class="mb-0"><i class="bi bi-chat-left-text"></i> 教师评语</h5>
                                    </div>
                                    <div class="card-body">
                                        ${submission.feedback ? 
                                            '<p class="mb-0">' + submission.feedback + '</p><p class="text-muted mt-2 small"><i class="bi bi-user"></i> ' + (submission.homework.course.teacher.user.realName || '教师') + ' <i class="bi bi-clock ml-2"></i> ' + (submission.feedbackTimeStr || '未知时间') + '</p>' :
                                            '<p class="text-muted mb-0">暂无教师评语</p>'
                                        }
                                    </div>
                                </div>
                            </div>
                        `;

                        document.getElementById('submissionDetails').innerHTML = detailsHTML;
                    } else {
                        document.getElementById('submissionDetails').innerHTML = '<div class="text-center py-5"><i class="bi bi-exclamation-circle text-danger" style="font-size: 2rem;"></i><p class="mt-3">' + (response.message || '获取作业详情失败') + '</p></div>';
                    }
                },
                error: function(xhr, status, error) {
                    console.error('获取作业详情失败:', error);
                    document.getElementById('submissionDetails').innerHTML = '<div class="text-center py-5"><i class="bi bi-exclamation-circle text-danger" style="font-size: 2rem;"></i><p class="mt-3">服务器错误，请重试</p></div>';
                }
            });

            // 显示模态框
            const modal = new bootstrap.Modal(document.getElementById('viewSubmissionModal'));
            modal.show();
        }

        // 确认删除作业
        window.deleteSubmission = function(id) {
            document.getElementById('deleteSubmissionId').value = id;
            const modal = new bootstrap.Modal(document.getElementById('confirmDeleteModal'));
            modal.show();
        }

        // 执行删除作业
        window.executeDeleteSubmission = function() {
            const id = document.getElementById('deleteSubmissionId').value;

            // 显示加载状态
            const deleteButton = document.querySelector('#confirmDeleteModal .btn-danger');
            const originalText = deleteButton.innerHTML;
            deleteButton.innerHTML = '<i class="bi bi-spinner bi-spin"></i> 删除中...';
            deleteButton.disabled = true;

            // 发送AJAX请求
            $.ajax({
                url: '${pageContext.request.contextPath}/student/homework/delete',
                method: 'POST',
                data: { submissionId: id },
                success: function(response) {
                    if (response.success) {
                        // 关闭模态框
                        const modal = bootstrap.Modal.getInstance(document.getElementById('confirmDeleteModal'));
                        modal.hide();

                        // 显示成功消息
                        showToast('success', response.message || '作业删除成功！');

                        // 刷新页面
                        setTimeout(() => {
                            location.reload();
                        }, 1500);
                    } else {
                        showToast('error', response.message || '作业删除失败，请重试！');
                    }
                },
                error: function(xhr, status, error) {
                    console.error('作业删除失败:', error);
                    showToast('error', '服务器错误，请重试！');
                },
                complete: function() {
                    // 恢复按钮状态
                    deleteButton.innerHTML = originalText;
                    deleteButton.disabled = false;
                }
            });
        }

        // 显示提示消息
        window.showToast = function(type, message) {
            // 创建toast元素
            const toastId = 'custom-toast-' + Date.now();
            
            // 根据类型确定样式
            let headerClass, iconClass, titleText;
            if (type === 'success') {
                headerClass = 'bg-success text-white';
                iconClass = 'bi-check-circle';
                titleText = '成功';
            } else if (type === 'error') {
                headerClass = 'bg-danger text-white';
                iconClass = 'bi-exclamation-circle';
                titleText = '错误';
            } else {
                headerClass = 'bg-primary text-white';
                iconClass = 'bi-info-circle';
                titleText = '提示';
            }
            
            const toastHTML = '<div id="' + toastId + '" class="toast position-fixed top-0 end-0 m-3" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="3000">' +
                '<div class="toast-header ' + headerClass + '">' +
                    '<i class="bi ' + iconClass + ' me-2"></i>' +
                    '<strong class="me-auto">' + titleText + '</strong>' +
                    '<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>' +
                '</div>' +
                '<div class="toast-body">' +
                    message +
                '</div>' +
            '</div>';

            // 添加到页面
            document.body.insertAdjacentHTML('beforeend', toastHTML);

            // 显示toast
            const toast = new bootstrap.Toast(document.getElementById(toastId));
            toast.show();

            // 自动移除
            setTimeout(() => {
                const element = document.getElementById(toastId);
                if (element) element.remove();
            }, 3500);
        }

        // 初始化折叠菜单
        document.querySelectorAll('.sidebar-menu > li').forEach(li => {
            const submenu = li.querySelector('.sidebar-submenu');
            if (submenu && submenu.querySelector('a.active')) {
                li.classList.add('open');
            }
        });

        // 初始化内容字数统计
        $('#homeworkContent').trigger('input');
    });
</script>
</body>
</html>

